# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

#
# 
# @param head ListNode类 the head
# @return bool布尔型
class Stack:
    def __init__(self):
        self.items = []
    def push(self, item):
        self.items.append(item)
    def pop(self):
        return self.items.pop()
    
class Solution:
    def isPail(self , head):
        # write code here
        if head.next == None:
           return True
        else:
            # 将所有元素放入栈区
            stack = self.toStack(head)
            # 进行判断
            while(head.next != None):
                i = stack.pop()
                print(f"{i} == {head.val}")

                if head.val != i:
                    return False
                head = head.next
            return True
    def toStack(self,head):
        stack = Stack()
        if head == None:
            return stack
        elif head.next == None:
            stack.push(head.next.val)
            return stack
        else:
            stack.push(head.val)
            while(head.next != None):
                head = head.next
                stack.push(head.val)
            return stack
